<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap3/css/bootstrap.min.css">
<script src="${pageContext.request.contextPath}/bootstrap3/js/jquery-1.11.2.min.js"></script>
<script src="${pageContext.request.contextPath}/bootstrap3/js/bootstrap.min.js"></script>
<script type="text/javascript">
	
	function checkForm(){/*
		var name=$("#name").val();
		var no=$("#no").val();
		var typeId=$("#typeId").val();
		var state=$("#state").val();
		if(name==null || name==""){
			$("#error").html("设备名称不能为空！");
			return false;
		}
		if(no==null || no==""){
			$("#error").html("设备编号不能为空！");
			return false;
		}
		if(typeId==null || typeId==""){
			$("#error").html("请选择设备类型！");
			return false;
		}
		if(state==null || state==""){
			$("#error").html("请选择设备状态！");
			return false;
		}*/
		return true;
	}
	
	
	function resetValue(){
		$("#name").val("");
		$("#no").val("");
		$("#typeId").val("");
		$("#state").val("");
		$("#remark").val("");
	}
function inpVal(){
	//IE 判定
	if ((navigator.userAgent.indexOf('MSIE') < 0) ){
		$("#tips").html('==>请在IE浏览器使用!');
		return;
	}
	//生成ActiveX对象
	var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); 
	var service = locator.ConnectServer(".");
	//CPU
	var properties = service.ExecQuery("SELECT * FROM Win32_Processor"); 
	var e = new Enumerator (properties); 
	var infoCPU="";
	for (;!e.atEnd();e.moveNext ()) { 
		var i = e.item ();
		infoCPU+=i.Name+'('+i.MaxClockSpeed+'MHz)';
	}
	//内存
    var memory = new Enumerator (service.ExecQuery("SELECT * FROM Win32_PhysicalMemory")); 
    for (var mem=[],i=0;!memory.atEnd();memory.moveNext()){ 
		mem[i++]={cap:memory.item().Capacity/1024/1024,speed:memory.item().Speed};
    }
    var infoDDR = 0;
    for(var mi=0;mi<mem.length;mi++){
    	infoDDR += mem[mi].cap;
	}
    infoDDR += 'MB';
    //MAC IP
    properties = service.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE");
 	e = new Enumerator (properties);
 	var infoIP='';
 	var infoMAC='';
	for (;!e.atEnd();e.moveNext ()){
	 var p = e.item ();
	 infoMAC+=p.MACAddress;
	 infoIP+=p.IPAddress(0);
	 i++;
	}
	
	//主板
	properties = service.ExecQuery("SELECT * FROM Win32_BaseBoard"); 
	e = new Enumerator (properties); 
	var infoBB="";
	for (;!e.atEnd();e.moveNext ()){
		 var p = e.item ();
		 infoBB=p.Product+'('+p.Manufacturer+')';
		 i++;
		}
	
	//硬盘
	properties = service.ExecQuery("SELECT * FROM Win32_DiskDrive"); 
	e = new Enumerator (properties); 
	var infoDD="";
	for (;!e.atEnd();e.moveNext ()){
		 var p = e.item ();
		 infoDD=parseInt(p.Size/1024/1024/1024)+'G';
		 i++;
		}
	
	//操作系统
	properties = service.ExecQuery("SELECT * FROM Win32_OperatingSystem"); 
	e = new Enumerator (properties); 
	var infoOS="";
	var infoCSN="";
	for (;!e.atEnd();e.moveNext ()){
		 var p = e.item ();
		 infoOS=p.Caption+" "+p.CSDVersion;
		 infoCSN=p.CSName;
		 i++;
		}
	
	$("#baseB").val(infoBB);
	$("#cpu").val(infoCPU);
	$("#memory").val(infoDDR);
	$("#DiskDrive").val(infoDD);
	$("#OperatingSystem").val(infoOS);
	$("#CSName").val(infoCSN);
	
	$("#MAC").val(infoMAC);
	$("#IP").val(infoIP);
}
</script>
</head>
<body>
<div style="margin: 5px;">
<button onclick="inpVal();">自动获取本机配置</button><span style="color: red" id="tips"></span><span id="warning"></span>
<form method="post" action="${pageContext.request.contextPath}/hardware/save.do">
<table class="table table-hover  table-bordered table-striped">
	<tr>
		<td>MAC地址：</td>
		<td><input type="text" id="MAC" name="mac" value="${hardware.mac }"/></td>
	</tr>
	<tr>
		<td>IP地址：</td>
		<td><input type="text" id="IP" name="ip" value="${hardware.ip }"/></td>
	</tr>
	<tr>
		<td>主板：</td>
		<td><input type="text" id="baseB" name="motherboard" value="${hardware.motherboard }"/></td>
	</tr>
	<tr>
		<td>CPU：</td>
		<td><input type="text" id="cpu" name="cpu" value="${hardware.cpu }"/></td>
	</tr>
	<tr>
		<td>内存：</td>
		<td><input type="text" id="memory" name="ram" value="${hardware.ram }"/></td>
	</tr>
	<tr>
		<td>硬盘：</td>
		<td><input type="text" id="DiskDrive" name="rom" value="${hardware.rom }"/></td>
	</tr>
	<tr>
		<td>操作系统：</td>
		<td><input type="text" id="OperatingSystem" name="os" value="${hardware.os }"/></td>
	</tr>
	<tr>
		<td>计算机名：</td>
		<td><input type="text" id="CSName" name="pcName" value="${hardware.pcName }"/></td>
	</tr>
	<tr>
		<td colspan="2" style="text-align: center;">
			<input type="hidden" id="id" name="id" value="${hardware.id }"/>
			<input type="hidden" id="devId" name="devId" value="${hardware.devId }"/>
			<button type="submit" class="btn btn-primary">保存</button>
		</td>
	</tr>
</table>
</form>
</div>
<!-- 
<div class="panel panel-default">
  <div class="panel-heading">
    <h3 class="panel-title">${actionName }</h3>
  </div>
  <div class="panel-body">
    <form class="form-horizontal" method="post" action="${pageContext.request.contextPath}/device/save.do" onsubmit="return checkForm()">
	  <div class="form-group">
	    <label class="col-sm-2 control-label">资产编码：</label>
	    <div class="col-sm-10">
	      <input type="text" class="form-control" id="name" name="assetId" value="${device.assetId }" style="width: 300px">
	    </div>
	  </div>
	  
	  <div class="form-group">
	    <label class="col-sm-2 control-label">资产名称：</label>
	    <div class="col-sm-10">
	      <input type="text" class="form-control" id="name" name="assetName" value="${device.assetName }" style="width: 300px">
	    </div>
	  </div>
	  
	  <div class="form-group">
	    <label class="col-sm-2 control-label">规格型号：</label>
	    <div class="col-sm-10">
	      <input type="text" class="form-control" id="name" name="type" value="${device.type }" style="width: 300px">
	    </div>
	  </div>
	  
	  <div class="form-group">
	    <label class="col-sm-2 control-label">计量单位：</label>
	    <div class="col-sm-10">
	      <input type="text" class="form-control" id="name" name="unitName" value="${device.unitName }" style="width: 300px">
	    </div>
	  </div>
	  
	  <div class="form-group">
	    <label class="col-sm-2 control-label">资产数量：</label>
	    <div class="col-sm-10">
	      <input type="text" class="form-control" id="name" name="assetNumber" value="${device.assetNumber }" style="width: 300px">
	    </div>
	  </div>
	  
	  <div class="form-group">
	    <label class="col-sm-2 control-label">入库时间：</label>
	    <div class="col-sm-10">
	      <input type="text" class="form-control" id="name" name="inTime" value="${device.inTime }" style="width: 300px">
	    </div>
	  </div>
	  
	  <div class="form-group">
	    <label class="col-sm-2 control-label">使用部门：</label>
	    <div class="col-sm-10">
	      <input type="text" class="form-control" id="name" name="useDepartment" value="${device.useDepartment }" style="width: 300px">
	    </div>
	  </div>
	  
	  <div class="form-group">
	    <label class="col-sm-2 control-label">安装地点：</label>
	    <div class="col-sm-10">
	      <input type="text" class="form-control" id="name" name="installationSite" value="${device.installationSite }" style="width: 300px">
	    </div>
	  </div>
	  
	  <div class="form-group">
	    <label class="col-sm-2 control-label">保管人：</label>
	    <div class="col-sm-10">
	      <input type="text" class="form-control" id="name" name="keeper" value="${device.keeper }" style="width: 300px">
	    </div>
	  </div>

	  <div class="form-group">
	    <div class="col-sm-offset-2 col-sm-10">
	      <input type="hidden" id="id" name="id" value="${device.id }"/>
	      <button type="submit" class="btn btn-primary">保存</button>&nbsp;&nbsp;
	      <button type="button" class="btn btn-primary" onclick="resetValue()">重置</button>&nbsp;&nbsp;
	      <font color="red" id="error"></font>
	    </div>
	  </div>
	  </form>
  </div>
</div>
 -->
</body>
</html>